package com.matrix.admin.controller;

import com.matrix.admin.service.AdminService;
import com.matrix.api.merchant.dto.MerchantReviewDTO;
import com.matrix.api.merchant.vo.MerchantApplicationVO;
import com.matrix.common.domain.PageResult;
import com.matrix.common.domain.Result;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author 有点甜
 * @since 2025/7/26
 */
@RestController
@RequestMapping("/admin/merchant")
@RequiredArgsConstructor
public class AdminController {

    private final AdminService adminService;

    @GetMapping("/applications")
    @PreAuthorize("hasAuthority('ADMIN')")
    public Result<PageResult<MerchantApplicationVO>> getApplications(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        return adminService.getMerchantApplications(pageNum, pageSize);
    }

    @PutMapping("/review")
    @PreAuthorize("hasAuthority('ADMIN')")
    public Result<Void> reviewApplication(@Valid @RequestBody MerchantReviewDTO reviewDTO) {
        adminService.reviewApplication(reviewDTO);
        return Result.success();
    }
}
